#include "shader/meshShader.h"

bool MeshShader::is_built = false;
GLuint MeshShader::ID;

MeshShader::MeshShader() {
	if(!is_built) {
		ID = load_shader("../shader/basicShader.vert", "../shader/basicShader.frag");
		is_built = true;
	}
}

void MeshShader::render(Mesh &mesh, glm::mat4 &modelMat, glm::mat4 &viewMat, glm::mat4 &projMat) const {
	glUseProgram(ID);
	glUniformMatrix4fv(glGetUniformLocation(ID, "model"), 1, GL_FALSE, glm::value_ptr(modelMat));
	glUniformMatrix4fv(glGetUniformLocation(ID, "view"), 1, GL_FALSE, glm::value_ptr(viewMat));
	glUniformMatrix4fv(glGetUniformLocation(ID, "proj"), 1, GL_FALSE, glm::value_ptr(projMat));
	glBindVertexArray(mesh.get_VAO());
	glDrawElements(GL_TRIANGLES, mesh.indices.size(), GL_UNSIGNED_INT, 0);
}